<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Home extends My_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('News_model', 'news');
        $this->load->model('Listing_model', 'listing');
        $this->load->helper('osc');
        $this->load->helper('html');
        $this->config->load('osc_config', TRUE);
        $this->load->library('session');
    }

    public function index() {
        $mobile = $this->input->get('mobile');
        if ($mobile)
            $this->session->set_userdata('mobile', 'off');
$config['image_library'] = 'gd2';
$config['source_image']	= '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']	 = 75;
$config['height']	= 50;

$this->load->library('image_lib', $config); 

$this->image_lib->resize();
        // getBannerSlide
        $data['bannerSlides'] = $this->listing->getBannerSlide();

        // save caculator
        // buildStateDropdown
        $js_state = 'id="calculator-state" ';
        $data['state'] = buildStateDropdown('calculator-state', $this->input->post('calculator-state'), 'QLD', $js_state);

        // buildStateDropdown
        $js_sales = 'id="calculator-sales"';
        $data['sales'] = buildSalesDropdown('calculator-sales', $this->input->post('calculator-sales'), '$250,000', $js_sales);

        // news home lastest
        $data['newshomelastest'] = $this->news->loadNewsHomeLatest();
        $data['newshomelastest_headline'] = $data['newshomelastest']["headline"];
        $data['newshomelastest_subject'] = $this->news->_substr($data['newshomelastest']["subject"], 99);

        //data for quick search
        $data['propertyType'] = $this->site->getArray('propertyType', 'Any');

        $data['BedroomCount'] = $this->site->getArray('featuteCount', 'Any');
        $data['BathroomCount'] = $this->site->getArray('featuteCount', 'Any');
        $data['Minprice'] = $this->site->getArray('priceRange', 'Any');
        $data['Maxprice'] = $this->site->getArray('priceRange', 'Any');
        $this->navigation->loadHomeView($data);
    }

    public function ajax_search() {
        $this->load->model('au_suburb_geo_model', 'suburb');
        $address = $_GET['part'];
        $data = $this->suburb->getAuSuburbGeo($address);

        $results = array();
        foreach ($data as $sub) {
            $results[$sub['ID']] = $sub['Locality'] . ' ' . $sub['State1'] . ', ' . $sub['Pcode'];
        }
        //var_dump($results);die;
        echo json_encode($results);



//$result = mysql_query("select * from au_suburb_geo where Locality like '%$q%' or Pcode like '%$q%' or State1 like '%$q%' order by Pcode LIMIT 25");
    }

    public function calculator_ajax() {
        $this->load->helper(array('form', 'url'));
        // save caculator
        $posts = $this->input->post();
        $state = $posts["calculator_state"];
        $sales = $posts["calculator_sales"];
        // config on config/osc_config.php
        $search_array_state_qld = $this->config->item('search_array_state_qld', 'osc_config');
        $search_array_state_others = $this->config->item('search_array_state_others', 'osc_config');
        $text_state_qld = $this->config->item('text_state_qld', 'osc_config');
        $text_state_others = $this->config->item('text_state_others', 'osc_config');

        if ($state == 'QLD') {
            $save_values = array_search($sales, $search_array_state_qld); // 
            echo json_encode(array('error' => '0', 'save_values' => $save_values, 'state_message' => $text_state_qld));
        } else {
            $save_values = array_search($sales, $search_array_state_others); // $key = 2;
            echo json_encode(array('error' => '0', 'save_values' => $save_values, 'state_message' => $text_state_others));
        }
    }
    
    public function deletecache($key){
        if($key='hjkuyy+45'){
        $this->load->model('listing_model', 'listing');
        $this->listing->deleteCache();
        return 1;
        }else{
        return 0;
        }
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
